<template>
  <div class="templateSetWrap">
    <div class="pageTableInner">
      <div v-if="$store.state.btnMenuIds.indexOf(69)>-1" class="infoSearchWrap">
        <div class="infoSearchOne">
          <el-row :gutter="20">
            <div style="float: right;margin-right: 10px;">
              <router-link to="/templateSet/addTemplate">
                <el-button
                  type="primary"
                  size="mini"
                >新增模板

                </el-button>
              </router-link>
            </div>
          </el-row>
        </div>
      </div>
      <div class="tableContainer" :style="$store.state.btnMenuIds.indexOf(69)>-1?'padding: 20px 20px 800px 20px;top: 75px;':'padding: 20px 20px 800px 20px;top: 0px;'">
        <div class="tableInner" ref="tableInner">
          <el-table
            ref="multipleTable"
            :data="rows"
            stripe
            :height="tableHeight"
            tooltip-effect="dark"
            style="width: 100%"
          >
            <el-table-column
              label="模板名称"
              prop="templateName"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="指标项"
              prop="itemCount"
            >
            </el-table-column>
            <el-table-column
              label="上次使用时间"
              prop="lastUseTime"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="创建时间"
              prop="createTime"
              show-overflow-tooltip>
            </el-table-column>

            <el-table-column
              label="操作"
            >
              <template slot-scope="scope">
                <router-link :to="'/templateSet/templateDetail/'+scope.row.templateId">
                  <i  class="iconfont icon-chakan" ></i>

                </router-link>
                <!--<el-button
                  style="margin-left: 10px;"
                  type="text"
                  size="mini"
                >下载
                </el-button>-->
                <i v-if="$store.state.btnMenuIds.indexOf(70)>-1" @click='handleDelete(scope.row)' class="iconfont icon-shanchu" style="margin-left: 10px;"></i>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>

    <router-view @getTempalteInfo="getTempalteInfo"></router-view>
  </div>
</template>

<script>


  export default {
    props: [],
    data(){
      return {
        rows: [],
        tableHeight:400,
      }
    },
    components: {},
    created(){
      this.getTempalteInfo()
    },
    mounted(){
      this.$nextTick(() => {
        //表格滚动
        let height=this.$store.state.userInfo.roleLevel==1?120:40
        this.tableHeight = document.querySelector(".templateSetWrap").clientHeight -height
      })
    },
    methods: {
      handleDelete(row){
        this.$confirm('确认删除模板 “' + row.templateName + '” , 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.axios.post(process.env.API_HOST + `/examine/deleteTemplate?`,{templateId:row.templateId})
            .then(response => {
              const result = response.data
              if (result.code === 200) {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
                this.getTempalteInfo()
              }
            })
        }).catch(() => {

        });
      },
      //获取所有信息
      getTempalteInfo(){
        this.axios.post(process.env.API_HOST + `/examine/selectTemplateGrid`,{})
          .then(response => {
            const result = response.data
            if (result.code == 200) {
              this.rows = result.rows
            }
          })
      },
    },
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "../../../common/stylus/mixin.styl"
  .templateSetWrap
    page()


</style>
